-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: support using
, link top-level using
declarations in components to lifecycle
#16192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8f5a073 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
using
, link top-level using declarations in components to lifecycleusing
, link top-level using
declarations in components to lifecycle
Fun idea from bsky — |
So that would be like a 1 time $derived value? |
Alternative to #16190, with the distinction that
using
declarations at the top level of a component are only disposed when the component unmounts.I think I prefer this — it's more useful and more intuitive. Demo here.
On the server it doesn't transform anything, meaning resources are correctly disposed of once rendering is complete. Obviously all this is of limited use until support is sufficiently widespread, but I don't see any reason to hold it back until then. (The demo above actually works in all browsers, because top-level
using
gets compiled away for client code, but that doesn't apply to server code or non-top-levelusing
.)Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint